<?php


namespace app\common\model;


use think\Model;

abstract class BaseModel extends Model
{
    protected $statusList = [];

    public function getStatusLists($field)
    {
        return $this->statusList[$field];
    }
    /**
     * 获取状态名称
     * @param $field
     * @param null $value
     * @return mixed
     */
    public function getStatusName($field, $value = null)
    {
        $list = $this->getStatusLists($field);
        if (!is_null($value)) {
            if (!isset($list[$value])) {
                return '';
            }
            $status = explode('|', $list[$value]);
            return $status[1] ?? $status[0];
        }
        return $list;
    }

    public function getStatusValue($field, $name = null)
    {
        $list = array_flip($this->getStatusLists($field));
        if (!is_null($name)) {
            foreach ($list as $key => $item) {
                $status = explode('|', $key);
                if ($status[0] === $name) {
                    return $item;
                }
            }
            return '';
        }
        return $list;
    }
}